package com.tchhy.provider.net.interceptor

import okhttp3.Interceptor
import okhttp3.Response
import android.text.TextUtils


/**
 * 更改主机即baseurl，不加协议 如：www.qihe.com
 *
 */
class DynamicHostInterceptor : Interceptor {
    companion object {
        @Volatile
        @JvmStatic
        var host: String = ""
    }

    override fun intercept(chain: Interceptor.Chain): Response {
        var request = chain.request()
        if (!TextUtils.isEmpty(host)) {
            request = request.url.newBuilder().host(host).build().run {
                request.newBuilder().url(this).build()
            }
        }
        return chain.proceed(request)
    }
}